#include "user_bt_a2dp.h"
#include "lvgl.h"
#include "FreeRTOS.h"
#include "app_lvgl.h"
#include "app_bt.h"
#include "user_bt.h"


#define BT_MUSIC_LOG    printf

user_bt_media_t bt_media;

void    user_bt_music_control(bt_enum_music_t control)
{
    BtStatus status;
    
    switch(control)
    {
        case BT_ENUM_MUSIC_PLAY:
            status = AVRCP_SetPanelKey(user_bt_env.dev[user_bt_env.last_active_index].rcp_chan, AVRCP_POP_PLAY, TRUE);
        break;

        case BT_ENUM_MUSIC_PAUSE:
            status = AVRCP_SetPanelKey(user_bt_env.dev[user_bt_env.last_active_index].rcp_chan, AVRCP_POP_PAUSE, TRUE);
        break;            

        case BT_ENUM_MUSIC_PREVIOUS:
            status = AVRCP_SetPanelKey(user_bt_env.dev[user_bt_env.last_active_index].rcp_chan, AVRCP_POP_FORWARD, TRUE);
        break;

        case BT_ENUM_MUSIC_NEXT:
            status = AVRCP_SetPanelKey(user_bt_env.dev[user_bt_env.last_active_index].rcp_chan, AVRCP_POP_BACKWARD, TRUE);
        break;

        default:
            break;           
    }
    BT_MUSIC_LOG("%s %d\r\n",__func__, status);
}

void    user_bt_sync_music_volume(uint8_t vol)
{
    uint8_t buf[3];
    printf("%s %d %d\r\n", __func__, vol,__LINE__);
    buf[0] = 'E';
    buf[1] = 'E';
    buf[2] = vol * 127/ 100;
    printf("%s %d %d\r\n", __func__, __LINE__,buf[2]);
    app_at_cmd_recv_handler(buf,NULL);
}


void    user_bt_set_music_playstatus(bool status)
{
	bt_media.play_status = status;
}    


bool    user_bt_get_music_playstatus(void)
{
	return bt_media.play_status;
} 

uint8_t     user_bt_get_music_vol(void)
{
	return bt_media.vol;
} 

void    user_bt_set_music_vol(uint8_t vol)
{
	bt_media.vol = vol;
} 

uint8_t *user_bt_get_music_songname(void)
{
    return &bt_media.song[0];
}


void user_bt_song_lyric_notify(void)
{
    gui_task_msg_send(MUSIC_CONTROL_EVT,NULL,0,NULL,0,NULL);
}


void    user_bt_get_media_info(void)
{
    BtStatus status;
    status = bt_get_media_info(user_bt_env.last_active_index,0x41);
    BT_MUSIC_LOG("%s %d\r\n",__func__, status);
}










